"""任务页面"""
from time import sleep

from page.base_page import BasePage
from selenium.webdriver.common.by import By
from page.index_page import IndexPage
from page.login_page import LoginPage


class TaskPage(BasePage):
    url='/crm5/index.php?m=task'
    #添加任务定位器
    btn_add_task_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(1) > div > a")
    #添加成功的文本定位器
    add_success_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    #添加失败的文本定位器
    add_file_locator=(By.CSS_SELECTOR,"body > div > form > fieldset > legend > h3")
    #任务工具定位器
    btn_tool_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > div > button")
    #导出任务定位器
    btn_export_locator = (By.ID, "excelExport")

    def click_add_task(self):
        """点击添加任务"""
        self.driver.find_element(*self.btn_add_task_locator).click()
    def success_tips_text(self):
        """成功返回的文本"""
        return self.driver.find_element(*self.add_success_locator).text
    def file_tips_text(self):
        """失败返回的文本"""
        return self.driver.find_element(*self.add_file_locator).text
    def click_btn_tool(self):
        """任务工具"""
        self.driver.find_element(*self.btn_tool_locator).click()
    def click_exptor(self):
        """导出任务选项"""
        self.driver.find_element(*self.btn_export_locator).click()


    def task_page(self, username, password):
        """封装“登录后进入任务页面”的公共流程"""
        #实例化登陆页面
        lp=LoginPage(self.driver)
        # 复用登录方法
        lp.login(username, password)
        #实例化主页页面
        ip = IndexPage(self.driver)
        #点击跳转任务页面
        ip.click_task()
        sleep(1)
